package com.example.hxpc.guidancemanagement.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.hxpc.guidancemanagement.R;
import com.example.hxpc.guidancemanagement.base.HonorInfo;
import com.example.hxpc.guidancemanagement.base.Message;
import com.example.hxpc.guidancemanagement.tools.LogoutT;

import java.util.List;

/**
 * Created by tao on 2017/12/1.
 */

public class MyListViewAdapter extends BaseAdapter{
    private List<HonorInfo> mList;
    private Context context;
    private LayoutInflater inflater;
    private List<Message> list;
    private boolean flg = false;//标识符，用于判断用哪个构造方法及使用哪个子布局
    public MyListViewAdapter(Context context,List<HonorInfo> mList){
        this.context = context;
        this.mList = mList;
        inflater = LayoutInflater.from(context);
    }

    public MyListViewAdapter(Context context ,List<Message> list , boolean flg){
        this.context = context;
        this.list = list;
        this.flg = flg;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if (flg == false){
            return mList.size();
        }else{
            return list.size();
        }
    }

    @Override
    public Object getItem(int position) {
        if (flg == false){
            return mList.get(position);
        }else {
            return list.get(position);
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
            if (convertView == null){
                holder = new ViewHolder();
                if (flg == false){
                    LogoutT.logout("okokok123");
                    convertView = inflater.inflate(R.layout.honor_list_item,null);
                    holder.te_title = (TextView) convertView.findViewById(R.id.te_title);
                    holder.te_details = (TextView) convertView.findViewById(R.id.te_details);
                    holder.img_avatar = (ImageView) convertView.findViewById(R.id.img_avatar);
                    convertView.setTag(holder);
                }else {
                     LogoutT.logout("okokok");
                    convertView = inflater.inflate(R.layout.message_item,null);
                    LogoutT.logout("好的好的");
                    holder.userName = (TextView) convertView.findViewById(R.id.te_userName);
                    holder.message = (TextView) convertView.findViewById(R.id.te_message);
                    convertView.setTag(holder);
                }
            }else{
                holder = (ViewHolder) convertView.getTag();
            }
        if (flg == false){
            holder.te_title.setText(mList.get(position).getTitle());
            holder.te_details.setText(mList.get(position).getDetails());
            holder.img_avatar.setImageResource(mList.get(position).getAvatar());
        }else {
            holder.userName.setText("涛：");
            holder.message.setText(list.get(position).getMessage());
        }
        return convertView;
    }

    public class ViewHolder{
        //荣誉版模块item信息
        public TextView te_title;
        public TextView te_details;
        public ImageView img_avatar;
        //活动模块留言item信息
        public TextView userName;
        public TextView message;
    }
}
